#!/usr/bin/env python3.10
# -*- encoding: utf-8 -*-
'''
@File    :   posts.py
@Time    :   2023/05/05 09:41:59
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib
from typing import List, Optional, Union
from datetime import datetime

from fastapi import Query
from pydantic import BaseModel,Field

from .base import BaseFilter, ORMModel

__all__ = ['PostTagStatus','TagStatus','CreatePost', 'UpdatePost', 'PostOut','PostInfo', 'PostFilter']

class PostTagStatus(BaseModel):
    tid: int
    # 关联表中的状态
    status: int
    
class TagStatus(PostTagStatus):
    name: str


class CreatePost(BaseModel):
    """ 创建文章 """
    title: str = Field(..., alias='postTitle')
    description: Optional[str] = None
    content: str = Field(..., alias='postContent')
    tags: List[PostTagStatus]


class UpdatePost(CreatePost):
    """ 更新文章 """
    pass

class PostOut(ORMModel):
    """ 文章基本信息 """
    id: int = Field(..., alias='postId', description='文章ID')
    title: str = Field(..., alias='postTitle', description='文章标题')
    description: Optional[str] = Field(None, alias='postDescription', description='文章摘要')
    content: str = Field(..., alias='postContent', description="文章内容")  
    created: datetime  = Field(..., alias='postCreated', description='文章创建时间')
    author: str = Field(..., alias='postAuthor', description='文章作者')
    
class PostInfo(PostOut):
    """ 文章详细信息 """
    tags: List[TagStatus]
    
class PostFilter(BaseFilter):
    """ 过滤文章 """
    title__icontains: Optional[str] = Query(None, alias="title", description="文章标题模糊查询")
    content__icontains: Optional[str] = Query(None, alias="content", description="文章内容模糊查询")
    description__icontains: Optional[str] = Query(None, alias="description",description="文章摘要模糊查询")
    

